package com.bosssoft.cloud.wechat.infrastructure.exception;

import com.bosssoft.cloud.wechat.infrastructure.enums.ErrEnum;
import com.bosssoft.cloud.wechat.infrastructure.enums.ReturnEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * 自定义顶级Base异常类
 * 异常类型的区分主要根据错误码
 *
 * @author wcy create on 2021/6/17 18:05 下午
 */
@Getter
@Setter
public class BaseException extends RuntimeException {

    private ReturnEnum errEnum = ErrEnum.B0001;

    public BaseException() {
        super();
    }

    public BaseException(ErrEnum errEnum) {
        super();
        this.errEnum = errEnum;
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(ErrEnum errEnum, String message) {
        super(message);
        this.errEnum = errEnum;
    }

    @Override
    public String toString() {
        return String.format("[%s] %s", errEnum.getCode(), errEnum.getMessage());
    }
}
